package com.wechat.ferry.controller;

import com.wechat.ferry.entity.TResponse;
import com.wechat.ferry.service.WxUserService;
import com.wechat.ferry.service.impl.ScriptRunner;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 控制层-微信消息处理
 *
 * @author chandler
 * @date 2024-10-01 14:25
 */
@Slf4j
@RestController
@RequestMapping("/wechat/custom")
@Api(tags = "自定义接口")
@AllArgsConstructor
public class CustomController {

    private WxUserService wxUserService;
    private ScriptRunner scriptRunner;

    @ApiOperation(value = "执行生日推送")
    @PostMapping(value = "/execBirthDay")
    public TResponse<Object> execBirthDay() {
        return TResponse.ok(wxUserService.execBirthDay());
    }

    /**
     * 测试消息推送
     *
     * @param msgText
     */
    @ApiOperation(value = "测试消息推送")
    @GetMapping(value = "/sendTextMsg")
    public TResponse<Object> sendTextMsg(String msgText) {
        wxUserService.sendTextMsg(msgText, Boolean.FALSE);
        return TResponse.ok("推送成功");
    }

    @ApiOperation(value = "初始化用户信息")
    @PostMapping(value = "/initUser")
    public TResponse<Object> initUser() {
        return TResponse.ok(wxUserService.initUser());
    }

    @ApiOperation(value = "初始化微信用户信息")
    @PostMapping(value = "/initWxUser")
    public TResponse<Object> initWxUser() {
        return TResponse.ok(wxUserService.initWxUser());
    }

    @ApiOperation(value = "执行早安心语")
    @PostMapping(value = "/execGoodMorningMessage")
    public TResponse<Object> execGoodMorningMessage() throws Exception {
        return TResponse.ok(wxUserService.execGoodMorningMessage());
    }

    @ApiOperation(value = "执行重启脚本")
    @GetMapping(value = "/runRestartScript")
    public TResponse runRestartScript() throws Exception {
        scriptRunner.runRestartScript();
        return TResponse.ok("脚本执行成功");
    }

}
